package com.hightrast.service.converToClassMapper;

import com.alibaba.fastjson.JSONObject;
import com.hightrast.service.api.domain.bo.QueryShopifyProduct;
import com.hightrast.service.api.entity.RastProductImages;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.List;

@Mapper
public interface ProductImageMapper {
    ProductImageMapper INSTANCE = Mappers.getMapper(ProductImageMapper.class);

    @Mapping(source = "id", target = "id")
    @Mapping(source = "alt", target = "alt")
    @Mapping(source = "position", target = "position")
    @Mapping(source = "product_id", target = "productId")
    @Mapping(source = "created_at", target = "createdAt")
    @Mapping(source = "updated_at", target = "updatedAt")
    @Mapping(source = "width", target = "width")
    @Mapping(source = "height", target = "height")
    @Mapping(source = "src", target = "src")
    @Mapping(source = "variant_ids", target = "variantIds")
    RastProductImages queryShopifyToProductImage(QueryShopifyProduct.ProductImages queryShopifyProduct);

    // 自定义方法：将 OffsetDateTime 转换为 LocalDateTime
    default LocalDateTime convertDateTime(OffsetDateTime offsetDateTime) {
        return offsetDateTime != null ? offsetDateTime.toLocalDateTime() : null;
    }

    default String convertVariantId(List<Long> variantIds) {
        return JSONObject.toJSONString(variantIds);
    }

    // 自定义转换方法：将 Boolean 转换为 Integer
    default Integer convertBoolean(Boolean value) {
        if(value == null){
            return null;
        }
        return value ? 1 : 0;
    }
}